#!/bin/sh -xe

# read core number
procs=`nproc --all`
echo `build use ${procs} cores`

# set cmake link
ln -s /opt/Qt/Tools/CMake/bin/cmake /usr/bin/cmake

# fix depend
apt install -y libglu1-mesa-dev
apt install -y libxcb-xkb-dev 
apt install -y libxkbcommon-dev 
apt install -y libxkbcommon-x11-dev
export PATH=$PATH:/opt/Qt/6.6.3/gcc_64/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt/6.6.3/gcc_64/lib
#echo "LD_LIBRARY_PATH=/opt/Qt/6.6.3/gcc_64/lib:\$LD_LIBRARY_PATH" >> /root/.bashrc
#echo "PATH=/opt/Qt/6.6.3/gcc_64/bin:\$PATH" >> /root/.bashrc
ln -s /usr/bin/python3 /usr/bin/python


# start to build
echo
echo '--> build CQtDeployer'
echo

# build cqtdeployer
cmake -S /workspace/CQtDeployer -B /workspace/CQtDeployer/build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/opt/Qt/6.6.3/gcc_64/lib/cmake
cd /workspace/CQtDeployer/build && make -j${procs}
make install
ln -s /usr/bin/CQtDeployer /usr/bin/cqtdeployer
cp /workspace/CQtDeployer/build/submodules/QuasarAppLib/libQuasarApp.so.1.5.3 /usr/lib

# build inja

echo
echo '--> build inja'
echo

cmake -S /workspace/inja -B /workspace/inja/build
cd /workspace/inja/build && make -j${procs}
make install

# build fluentui
echo
echo '--> build fluentui'
echo

cmake -S /workspace/FluentUI -B /workspace/FluentUI/build -DCMAKE_PREFIX_PATH=/opt/Qt/6.6.3/gcc_64/lib/cmake
cd /workspace/FluentUI/build && make -j${procs}




